home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / stdg44.exe / lha / DEMO.C < prev    next >
C/C++ Source or Header  |  1994-01-10  |  5KB  |  216 lines

  1. #include <stdio.h>
  2. #include "stdg.h"
  3.  
  4. /* Press space repeatedly to see a demo of the library's features */
  5.  
  6. #define NORMAL_TEST 1
  7. #define USE_RESOURCES 0
  8.  
  9. void cont(char *);
  10. void putstring(char *);
  11.  
  12. unsigned char arrowbits[] =
  13.     {0x00, 0x00, 0x7F, 0xC0, 0x7F, 0x00, 0x7C, 0x00,
  14.      0x7E, 0x00, 0x7F, 0x00, 0x6F, 0x80, 0x67, 0xC0,
  15.      0x43, 0xE0, 0x41, 0xF0, 0x00, 0xF8, 0x00, 0x7C,
  16.      0x00, 0x3E, 0x00, 0x1C, 0x00, 0x08, 0x00, 0x00};
  17.  
  18. char *colornames[] = { "Black", "Blue", "Red", "Magenta",
  19.         "DkGrey", "Grey", "LtGrey", "Green", "Cyan", "Yellow", "White" };
  20. pixval colordefs[] = { BLACK, BLUE, RED, MAGENTA,
  21.         DKGREY, GREY, LTGREY, GREEN, CYAN, YELLOW, WHITE };
  22.  
  23. #define Ncol (sizeof(colordefs)/sizeof(pixval))
  24.  
  25. window *w;  /* main window */
  26.  
  27. int main(int argc, char **argv)
  28. {
  29.     point p1,p2,p3;
  30.     mouse m;
  31.     int r,rx,ry;
  32.     int n, i;
  33.     char *p, buf[200];
  34.     bitmap *bm, *bm2;
  35.  
  36.     ginit("Tester", NULL, NULL);
  37.     w = new_window("Tester", rect(0,0,0,0),
  38.                     Titlebar+Resize+Maximize);
  39.     show_window(w);
  40.  
  41.     p1 = addp(w->b->r.min, pt(15,15));
  42.     p2 = subp(w->b->r.max, pt(15,15));
  43.  
  44. #if NORMAL_TEST
  45.  
  46.     draw_line(w->b, p1, p2, BLACK);
  47.  
  48.     cont("draw_point");
  49.     draw_point(w->b, p1, BLACK);
  50.  
  51.     cont("draw_rect");
  52.     draw_rect(w->b, insetr(w->b->r, 4), 2, GREY);
  53.  
  54.     cont("draw_circle");
  55.     p3 = divp(addp(p1,p2),2);
  56.     rx = p3.x - p1.x;
  57.     ry = p3.y - p1.y;
  58.     r = (rx < ry)? rx : ry;
  59.     draw_circle(w->b, p3, r, BLACK);
  60.  
  61.     cont("fill_circle");
  62.     fill_circle(w->b, p3, r, GREY);
  63.  
  64.     cont("draw_ellipse");
  65.     draw_ellipse(w->b, p3, r, r/2, BLACK);
  66.  
  67.     cont("draw_arc");
  68.     draw_arc(w->b, p3, pt(p3.x+r,p3.y), pt(p3.x+r/2,p3.y-(int)(r*.866)), BLACK);
  69.  
  70.     cont("color");
  71.     p3 = p1;
  72.     rx *= 2;
  73.     ry *= 2;
  74.     for(i = 0; i<Ncol; i++) {
  75.         fill_rect(w->b, rpt(p3,addp(p3,pt(rx,ry/Ncol))), colordefs[i]);
  76.         draw_string(w->b, addp(p3,pt(15,5)), sys_font,
  77.                 colornames[i], colordefs[Ncol-i-1]);
  78.         p3.y += ry/Ncol;
  79.     }
  80.  
  81. #endif
  82.  
  83. #if USE_RESOURCES
  84.  
  85.     cont("get_bitmap, draw_rect, and bit_copy(S)");
  86.     p3 = p1;
  87.  
  88.     set_cursor(get_cursor("Hand"));
  89.  
  90.     bm = get_bitmap("Circles", 1);
  91.     draw_rect(w->b, raddp(bm->r, p3), -2, BLACK);
  92.     bit_copy(w->b, p3, bm, bm->r, S);
  93.     del_bitmap(bm);
  94.  
  95.     p3.x += 48;
  96.  
  97.     bm = get_bitmap("Circles", 4);
  98.     draw_rect(w->b, raddp(bm->r, p3), -2, BLACK);
  99.     bit_copy(w->b, p3, bm, bm->r, S);
  100.     del_bitmap(bm);
  101.  
  102.     p3.x += 48;
  103.  
  104.     bm = get_bitmap("Circles", 8);
  105.     draw_rect(w->b, raddp(bm->r, p3), -2, BLACK);
  106.     bit_copy(w->b, p3, bm, bm->r, S);
  107.     del_bitmap(bm);
  108.  
  109.     p3.x += 48;
  110.  
  111.     bm = get_bitmap("Circles", 0);
  112.     draw_rect(w->b, raddp(bm->r, p3), -2, BLACK);
  113.     bit_copy(w->b, p3, bm, bm->r, S);
  114.     del_bitmap(bm);
  115.  
  116.     p3 = p1;
  117.     p3.y += 48;
  118.  
  119.     bm = get_bitmap("Small Circles", 1);
  120.     draw_rect(w->b, raddp(bm->r, p3), -2, BLACK);
  121.     bit_copy(w->b, p3, bm, bm->r, S);
  122.     del_bitmap(bm);
  123.  
  124.     p3.x += 48;
  125.  
  126.     bm = get_bitmap("Small Circles", 4);
  127.     draw_rect(w->b, raddp(bm->r, p3), -2, BLACK);
  128.     bit_copy(w->b, p3, bm, bm->r, S);
  129.     del_bitmap(bm);
  130.  
  131.     p3.x += 48;
  132.  
  133.     bm = get_bitmap("Small Circles", 8);
  134.     draw_rect(w->b, raddp(bm->r, p3), -2, BLACK);
  135.     bit_copy(w->b, p3, bm, bm->r, S);
  136.     del_bitmap(bm);
  137.  
  138.     p3.x += 48;
  139.  
  140.     bm = get_bitmap("Small Circles", 0);
  141.     draw_rect(w->b, rdiag(p3.x, p3.y, 16, 16), -2, BLACK);
  142.     bit_copy(w->b, p3, bm, bm->r, S);
  143.     del_bitmap(bm);
  144.  
  145.     bm = get_bitmap("Colour PICT", 0);
  146.     bit_copy(w->b, addp(p1,pt(0,96)), bm, bm->r, S);
  147.     del_bitmap(bm);
  148.  
  149. #endif /* USE_RESOURCES */
  150.  
  151.     cont("mouse track (button 1)");
  152.     do{
  153.         m = get_mouse(w);
  154.     } while(!(m.buttons&1));
  155.     while(m.buttons&1){
  156.         draw_point(w->b, m.xy, BLACK);
  157.         gflush();
  158.         m = get_mouse(w);
  159.     }
  160.     set_cursor(NULL);
  161.  
  162.     cont("keyboard (end with \\n)");
  163.     for (p = buf; (*p = get_key(w)) != '\n';) {
  164.         if (*p == '\b') {
  165.             p -= 2;
  166.             if (p < buf)
  167.                 p = buf-1;
  168.         }
  169.         p++;
  170.         *p = '\0';
  171.         putstring(buf);
  172.     }
  173.  
  174.     cont("done");
  175.     hide_window(w);
  176.  
  177.     return 0;
  178. }
  179.  
  180. void putstring(char *buf)
  181. {
  182.     point p;
  183.     static int jmax = 0, l;
  184.  
  185.     p = addp(w->b->r.min, pt(20,20));
  186.     fill_rect(w->b, rect(p.x, p.y, p.x+jmax, p.y+sys_font->height*2), WHITE);
  187.     draw_string(w->b, p, sys_font, buf, BLACK);
  188.     draw_string(w->b, pt(p.x,p.y+sys_font->height), sys_font, buf, GREY);
  189.     if ((l = strwidth(sys_font, buf)) > jmax)
  190.         jmax = l;
  191.     gflush();
  192. }
  193.  
  194. void cont(char *msg)
  195. {
  196.     point mp;
  197.     mouse m;
  198.  
  199.     gflush();
  200.     while(!can_key(w))
  201.         continue;
  202.     get_key(w);
  203.  
  204.     fill_rect(w->b, w->b->r, WHITE);
  205.     mp = addp(w->b->r.min, pt(20,20));
  206.     draw_string(w->b, mp, fixed_font, msg, BLACK);
  207.     gflush();
  208.  
  209.     while(!can_key(w))
  210.         continue;
  211.     get_key(w);
  212.  
  213.     fill_rect(w->b, w->b->r, WHITE);
  214.     gflush();
  215. }
  216.